import { TrayIcon } from '@tauri-apps/api/tray'
import createMenu from './createMenu'

/**
 * 在这里你可以添加一个托盘菜单，标题，工具提示，事件处理程序等
 */
const options = {
  // tray icon Relative path：project/src-tauri/
  icon: 'icons/icon.png',
  iconAsTemplate: true,
  // tray title tips
  tooltip: 'hClock',
  menuOnLeftClick: true,
  // tray menu - menuitem - submenu
  menu: undefined,
  // tray event
  action: event => {
    // event 包含以下属性：
    // type: 'Click' | 'DoubleClick' | 'Enter' | 'Move' | 'Leave'
    if (event.type === 'Click' && event.buttonState === 'Up') {
      console.log('单击事件', event)
    }
  },
}

/**
 * create system tray
 */
export async function createTray() {
  // options.menu = await createMenu()
  const tray = await TrayIcon.new(options)
  tray.id = 'tray'
  tray.setMenu(await createMenu())
  tray.setVisible(true)
  tray.setMenuOnLeftClick(true)
  console.log('%c Line:51 🍩 系统托盘创建成功', 'color:#2eafb0', tray)
}
